package com.zengqingfa.juc.n4.lock8;

import lombok.extern.slf4j.Slf4j;

/**
 * @fileName: ThreadLock1
 * @author: zengqf3
 * @date: 2021-6-10 9:41
 * @description:
 */
@Slf4j(topic = "c.ThreadLock1")
public class ThreadLock1 {

    public synchronized void method1() {
        log.debug("method1....");
    }

    public synchronized void method2() {
        log.debug("method2....");
    }

    public static void main(String[] args) {
        /**
         * 情况一：
         * 09:43:46:092 [Thread-0] c.ThreadLock1 - method1....
         * 09:43:46:092 [Thread-1] c.ThreadLock1 - method2....
         *
         * 情况二：
         * 09:44:51:841 [Thread-1] c.ThreadLock1 - method2....
         * 09:44:51:841 [Thread-0] c.ThreadLock1 - method1....
         *
         */
        ThreadLock1 lock = new ThreadLock1();
        new Thread(() -> {
            lock.method1();
        }).start();
        new Thread(() -> {
            lock.method2();
        }).start();
    }
}
